<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>

<body>
    <div id="container">
        <button class="d">删除事件</button>
        <button class="y">确认</button>
    </div>
    <script type="text/javascript">
	    window.onload = function() {
	        var container = document.getElementById("container");
	        var y = container.children[1];
	        var d = container.children[0];
	        var handler = [function(event) {
	                console.log(1);
	            },
	            function(event) {
	                console.log(2);
	            }
	        ]

	        EventUtil.addListener(y, "click", handler[0]);
	        EventUtil.addListener(y, "click", handler[1]);
	        EventUtil.addListener(d, "click", function(){
	        	EventUtil.removeListener(y, "click", handler[1]);
	        });
	        EventUtil.trigger(y,"click","Events");
	    }
	    var EventUtil = {
	    	trigger: function(element,type,eventName){
	    		if(element[type]){
	    			element[type]();
	    		}else{
	    			var e = document.createEvent(eventName);
	    			e.initEvent(type,true,true);
	    			element.dispatchEvent(e);
	    		}
	    	},
	        addListener: function(element, type, callback) {
	            if (element.addEventListener) {
	                element.addEventListener(type, callback);
	            } else if (element.attachEvent) {
	                element.attachEvent("on" + type, callback);
	            } else {
	                element["on" + type] = callback;
	            }
	        },
	        removeListener: function(element, type, callback) {
	            if (element.removeEventListener) {
	                element.removeEventListener(type, callback);
	            } else if (element.detachEvent) {
	                element.detachEvent("on" + type, callback);
	            } else {
	                element["on" + type] = undefined;
	            }
	        }
	    }
    </script>
</body>

</html>